<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/album/ShowUpload.class.php
 *
 * 显示相册上传界面
 *
 * PHP Version 5
 *
 * @package:   class.album
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';
include_once CLASS_PATH.'user/UserUtil.class.php';

//包含相册的工具表
include_once CLASS_PATH.'album/AlbumUtil.class.php';



class ShowUpload extends BaseAction {
   /**
    * 数据库的连接
    */
   private $db;


   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }


   /**
    * 上传相册的界面
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {
      $smarty = $this->getSmarty();

      $dir = $this->getParameterFromGET("dir");

      
      $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
      $user_name = $_SESSION['user']['name'];

      $smarty->assign('user_id', $user_id);
      $smarty->assign('album_user_name', $user_name);


      $dir_array = AlbumUtil::getUserDir($this->db, $user_id);

      if ( count($dir_array) <= 0 ) {
         $this->AlertAndBack('请先最少创建一个目录，然后将您的相片上传到目录里.');
         return;
      }

      if ( !$dir ) {
         $dir = $dir_array[0]['id'];
      }

      $dir_name = AlbumUtil::getDirName($this->db, $dir);
      $smarty->assign('dir_id', $dir);
      $smarty->assign('dir_name', $dir_name);

      $dir_option = "";

      foreach ( $dir_array as $dir_temp ) {
         $dir_option .= "<option value=\"".$dir_temp['id']."\"";

         if ( $dir == $dir_temp['id'] ) {
            $dir_option .= " selected ";
         }

         $dir_option .= ">".$dir_temp['name']."</option>\n";
      }


      $smarty->assign('dir_option', $dir_option);

      //得到所有的分类
      $type_info = AlbumUtil::getAllCategory($this->db);


      $type_option = "";

      for($i=0; $i<count($type_info); $i++ ) {
         $type_option .= "<option value=\"".$type_info[$i]['id']."\">".
            $type_info[$i]['name']."</option>\n";
      }

      $smarty->assign('type_option', $type_option);

      //为SEO设置
      $smarty->assign('clone_title', $user_name.'的相册管理->上传相片/5anet.com' );
      $smarty->assign('header_meta_content', $user_name.'的相册管理->上传相片/5anet.com' );




      $smarty->display('showuploadalbum.tmpl');


   }

}


?>
